package it.mauriziulu.android.ehttpexecutors.handler;

import it.mauriziulu.android.ehttpexecutors.request.EHttpRequest;
import it.mauriziulu.android.ehttpexecutors.response.EHttpResponseContainer;

import java.io.IOException;

import android.webkit.URLUtil;

public class URLVerifierHandler implements EResponseHandler {

	@Override
	public void handle(EHttpRequest request, EHttpResponseContainer response, ResponseHandlerChain chain) throws IOException {
		if (URLUtil.isValidUrl(request.getRequestLine().getUri())) {
			response.addMessage("URI[" + request.getRequestLine().getUri() + "] OK");
			chain.doHandle(request, response);
		} else {
			response.addMessage("URI not valid");
			throw new IOException("URI not valid");
		}
	}

}
